import redis


class Redis:
    def __init__(self):
        self.conn = redis.Redis(host='localhost', port=6379, db=1)

    # 存
    def set_str(self, mobile, codes, time=0):
        if time == 0:
            self.conn.set(mobile, codes)
        else:
            self.conn.setex(mobile, time, codes)

    # 取
    def get_str(self, mobile):
        value = self.conn.get(mobile)
        if value:
            value = str(value, encoding='utf8')
        return value

    #删
    def del_str(self,mobile):
        self.conn.delete(mobile)


r = Redis()
# r.set_str(123,'789',60)
# r.del_str(123)
# print(r.get_str(123))
